package edu.towsom.cosc.cosc455.ksmith73;

import java.util.Scanner;
import java.io.*;

public class Compiler {
	
	public static void main(String[] args) {
		
		//Declarations
		public String mkd;
		private MySyntaxAnalyzer Syntax = new MySyntaxAnalyzer();
		private MySemanticAnalyzer Semantic = new MySemanticAnalyzer();
		private MyLexicalAnalyzer Lexical = new MyLexicalAnalyzer();
		
		//Take in input
		public void read() throws IOException, CompilerException{
			Scanner in = new Scanner(System.in);
			String file;
			System.out.println("Enter the file name: ");
			file = in.next();
			BufferedReader read = new BufferedReader(new FileReader(file));
			try {
				StringBuilder build = new StringBuilder();
				String line = read.readLine();
				while (line != null){
				build.append(line);
				build.append("/n");
				line = read.readLine();
					}
				mkd = build.toString();
			} 
			finally {
					read.close();
			}
			Syntax.document();
				}
		//Output resulting document
		public void write(){
			BufferedWriter Writer = null;
			try {
				Writer = new BufferedWriter( new FileWriter("Final.txt"));
				while(!Semantic.html.empty());{
					Writer.write(Semantic.html.pop());
				}
			}
		}
		catch ( IOException e){
		}
		finally {
			try{
				if (Writer!= null){
					Writer.close();
				}
			}
			catch (IOException e){
			}
		}
		
		//Read the file
		Compiler.read();

	}
}
